From b3ecd290903bbebf357a22719834d65f21982593 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 28 Jan 2004 23:49:10 +0000 Subject: [PATCH] Do reference counting on the user_data that is shared between multiple Thu Jan 29 00:48:47 2004 Matthias Clasen * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference counting on the user_data that is shared between multiple signal handlers, to avoid calling the destroy notify multiple times. (#132447, Adam Hooper) --- ChangeLog | 7 +++++ ChangeLog.pre-2-10 | 7 +++++ ChangeLog.pre-2-4 | 7 +++++ ChangeLog.pre-2-6 | 7 +++++ ChangeLog.pre-2-8 | 7 +++++ gtk/gtkactiongroup.c | 65 ++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf90bbfead..4c5453b47e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Jan 29 00:48:47 2004 Matthias Clasen + + * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): + * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference + counting on the user_data that is shared between multiple signal handlers, + to avoid calling the destroy notify multiple times. (#132447, Adam Hooper) + 2004-01-28 Hans Breuer * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ... diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index bf90bbfead..4c5453b47e 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Thu Jan 29 00:48:47 2004 Matthias Clasen + + * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): + * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference + counting on the user_data that is shared between multiple signal handlers, + to avoid calling the destroy notify multiple times. (#132447, Adam Hooper) + 2004-01-28 Hans Breuer * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ... diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index bf90bbfead..4c5453b47e 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Thu Jan 29 00:48:47 2004 Matthias Clasen + + * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): + * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference + counting on the user_data that is shared between multiple signal handlers, + to avoid calling the destroy notify multiple times. (#132447, Adam Hooper) + 2004-01-28 Hans Breuer * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ... diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index bf90bbfead..4c5453b47e 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Thu Jan 29 00:48:47 2004 Matthias Clasen + + * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): + * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference + counting on the user_data that is shared between multiple signal handlers, + to avoid calling the destroy notify multiple times. (#132447, Adam Hooper) + 2004-01-28 Hans Breuer * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ... diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index bf90bbfead..4c5453b47e 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Thu Jan 29 00:48:47 2004 Matthias Clasen + + * gtk/gtkactiongroup.c (gtk_action_group_add_toggle_actions_full): + * gtk/gtkactiongroup.c (gtk_action_group_add_actions_full): Do reference + counting on the user_data that is shared between multiple signal handlers, + to avoid calling the destroy notify multiple times. (#132447, Adam Hooper) + 2004-01-28 Hans Breuer * gtk/stock-icons/stock_network_(16|24).png : new GTK_STOCK_NETWORK ... diff --git a/gtk/gtkactiongroup.c b/gtk/gtkactiongroup.c index 72ff6e4dfa..fb172cef3d 100644 --- a/gtk/gtkactiongroup.c +++ b/gtk/gtkactiongroup.c @@ -679,6 +679,29 @@ gtk_action_group_add_actions (GtkActionGroup *action_group, user_data, NULL); } +typedef struct _SharedData SharedData; + +struct _SharedData { + guint ref_count; + gpointer data; + GDestroyNotify destroy; +}; + +static void +shared_data_unref (gpointer data) +{ + SharedData *shared_data = (SharedData *)data; + + shared_data->ref_count--; + if (shared_data->ref_count == 0) + { + if (shared_data->destroy) + (*shared_data->destroy) (shared_data->data); + + g_free (shared_data); + } +} + /** * gtk_action_group_add_actions_full: @@ -707,12 +730,18 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group, guint i; GtkTranslateFunc translate_func; gpointer translate_data; + SharedData *shared_data; g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); translate_func = action_group->private_data->translate_func; translate_data = action_group->private_data->translate_data; + shared_data = g_new0 (SharedData, 1); + shared_data->ref_count = 1; + shared_data->data = user_data; + shared_data->destroy = destroy; + for (i = 0; i < n_entries; i++) { GtkAction *action; @@ -736,15 +765,24 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group, entries[i].stock_id); if (entries[i].callback) - g_signal_connect_data (action, "activate", - entries[i].callback, - user_data, (GClosureNotify)destroy, 0); + { + GClosure *closure; + + closure = g_cclosure_new (entries[i].callback, user_data, NULL); + g_closure_add_finalize_notifier (closure, shared_data, + (GClosureNotify)shared_data_unref); + shared_data->ref_count++; + g_signal_connect_closure (action, "activate", closure, FALSE); + } + gtk_action_group_add_action_with_accel (action_group, action, entries[i].accelerator); g_object_unref (action); } + + shared_data_unref (shared_data); } /** @@ -801,12 +839,18 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group, guint i; GtkTranslateFunc translate_func; gpointer translate_data; + SharedData *shared_data; g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); translate_func = action_group->private_data->translate_func; translate_data = action_group->private_data->translate_data; + shared_data = g_new0 (SharedData, 1); + shared_data->ref_count = 1; + shared_data->data = user_data; + shared_data->destroy = destroy; + for (i = 0; i < n_entries; i++) { GtkToggleAction *action; @@ -832,15 +876,24 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group, gtk_toggle_action_set_active (action, entries[i].is_active); if (entries[i].callback) - g_signal_connect_data (action, "activate", - entries[i].callback, - user_data, (GClosureNotify)destroy, 0); + { + GClosure *closure; + + closure = g_cclosure_new (entries[i].callback, user_data, NULL); + g_closure_add_finalize_notifier (closure, shared_data, + (GClosureNotify)shared_data_unref); + shared_data->ref_count++; + g_signal_connect_closure (action, "activate", closure, FALSE); + } + gtk_action_group_add_action_with_accel (action_group, GTK_ACTION (action), entries[i].accelerator); g_object_unref (action); } + + shared_data_unref (shared_data); } /** -- 2.30.2